<?php
namespace Home\Controller;
use Think\Controller;

class SigninH5Controller extends  BaseController


{
	public function index(){
		
		$root = get_baseroot();
		$user_id  =  trim($GLOBALS['request']['user_id']);
		$user = get_user_info("*","id = ".intval($user_id));
		
		if ($user_id >0){
			//$root['result'] = signin($user_id);
			$root['response_code'] = "1";
			$root['show_err'] = '';
			
			//用户总积分
			$root['score'] =$user['score'];
			//本月已签日期
			$month = to_date(TIME_UTC,"Y-m");  //年月
			$month_s = $month.'-01'; //月第一天
			$t_begin_time = to_timespan($month_s);
			$t_end_time = $t_begin_time + (24*3600*31 - 1);  //31天
			$days = $GLOBALS['db']->getAll("select * from ".DB_PREFIX."user_sign_log where user_id = ".$user_id." and sign_date between ".$t_begin_time." and ".$t_end_time);
			$day_count =  $GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."user_sign_log where user_id = ".$user_id);
			
			//处理下日期
			$sign_days=array();
			foreach($days as $k => $v)
				{
					if ($v['sign_date'] != '' &&strpos(to_date($v['sign_date'],'Y-m-d'),$month) !== false){
						$sign_days[]['signDay'] = to_date($v['sign_date'],'d');	
					}					
				}
			$root['sign_days'] = json_encode($sign_days);
			$root['day_count'] = $day_count;
		}else{
			$root['response_code'] = "0";
			$root['show_err'] ="未登录";
			$root['signin_status'] = "1";
		}
		
		
		$root['program_title'] = "签到";
		output($root);		
		// echo($root['sign_days']);
	}
	
}
?>

